package com.example.utils;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

public class CodeGenerator {

    public static void main(String[] args) {
        // 数据库连接信息
        String url = "jdbc:mysql://localhost:3306/book_lending_history?serverTimezone=UTC";
        String username = "root";
        String password = "yht267256";

        // 项目模块名
        String module = "teacher";

        // 全局配置参数
        String author = "yht";
        String outputDir = System.getProperty("user.dir") + "/" + module +"/src/main/java/";

        // 开始生成
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> builder
                        .author(author)
                        .outputDir(outputDir)
                        .commentDate("yyyy-MM-dd")
                )
                .packageConfig(builder -> builder
                        .parent("com.example")
                        .entity("entity")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
                        .xml("mapper.xml")
                )
                .strategyConfig(builder -> builder
                        .entityBuilder()
                        .enableLombok()
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
